﻿@inherits SusuCMS.Web.Front.WidgetPageBase

@using Winista.Text.HtmlParser
@using Winista.Text.HtmlParser.Filters
@using Winista.Text.HtmlParser.Lex
@{
    
    var domain = Request.QueryString["domain"];
    if (!String.IsNullOrWhiteSpace(domain))
    {
        try
        {
            using (var client = new WebClient())
            {
                client.Encoding = System.Text.UTF8Encoding.UTF8;
                var html = client.DownloadString(new Uri("http://whois.elmundo.es/whois/cgi/whois.html?q=" + domain));
                var parser = new Parser(new Lexer(html));
                var nodes = parser.ExtractAllNodesThatMatch(new TagNameFilter("td"));
                for (var i = 0; i < nodes.Count; i++)
                {
                    var tag = nodes[i] as ITag;
                    if (tag != null && tag.GetAttribute("bgcolor") == "#d0d0d0")
                    {
                        ViewBag.Result = tag.ToHtml();
                        break;
                    }
                }
            }
        }
        catch
        {
            ViewBag.Result = WidgetLabel("No result");
        }
    }
}
<h2>
    @WidgetLabel("Domain whois")</h2>
<div class="description">
    @WidgetLabel(@"Just enter the domain name, you can easily check whether the domain name has been registered, and the domain name registrant, registration date, expiration date, domain state, registrars, DNS servers and other related registration information.")
</div>
<p>
    @WidgetLabel("Enter domain such as susucms.com without www")
</p>
<form action="@Request.Url.AbsolutePath" method="get">
@Html.TextBox("domain", domain)
<p class="buttons">
    <button type="submit">
        @WidgetLabel("Query")</button>
</p>
</form>
<p>
    @Html.Raw(ViewBag.Result)
</p>
